﻿using CustomCommons;
using MediatR;
using Production.Api.Read.Application.Command.StudentCommand;
using ProductionDomain;
using SqlSugar;

namespace Production.Api.Read.Application.CommandHandler.StudentCommandHandler
{
    public class StudentCommandHandler : IRequestHandler<StudentQueryCommand, ApiResult<List<Student>>>
    {
        private readonly ISqlSugarClient db;
        public StudentCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }
        public async Task<ApiResult<List<Student>>> Handle(StudentQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<Student>>();
            List<Student> list = db.Queryable<Student>().ToList();
            result.Success(list);
            return result;
        }

    }
}
